package handler

import (
	"chat/api/requset"
	"chat/consts"
	"chat/internal/dao"
	"chat/internal/model"
	"chat/internal/queue"
	"github.com/gin-gonic/gin"
	"net/http"
)

func SendMessage(c *gin.Context) {
	var req requset.SendMessageReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"data": err.Error(),
		})
		return
	}
	message := model.SystemMessage{
		Title:   req.Title,
		Content: req.Content,
	}
	dao.Create(&message)
	go queue.PublishPub(consts.WS_ES, message)
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "公告发布成功",
		"data": true,
	})
}
